<?php

namespace app\common\model;

use think\Model;


class Options extends Model
{

    

    

    // 表名
    protected $name = 'options';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
//        'trigger_type_text',
//        'status_text'
    ];
    

    protected static function init()
    {
        self::afterInsert(function ($row) {
            $pk = $row->getPk();
            $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
        });
    }

    
    public function getTriggerTypeList()
    {
        return ['""' => __('Trigger_type ""'), 'redirect' => __('Trigger_type redirect'), 'submit' => __('Trigger_type submit'), 'hide' => __('Trigger_type hide')];
    }

    public function getStatusList()
    {
        return ['hidden' => __('Status hidden'), 'normal' => __('Status normal')];
    }


    public function getTriggerTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['trigger_type']) ? $data['trigger_type'] : '');
        $list = $this->getTriggerTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }



    public function project()
    {
        return $this->belongsTo('Project', 'project_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }





}
